import requests
import json
from config import Config

def dify_ai_reply(msg):
    url = Config.BASE_URL

    payload = json.dumps(msg)
    headers = {
        'Authorization': f'Bearer {Config.API_KEY}',
        'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
        'Content-Type': 'application/json'
    }

    try:
        response = requests.request("POST", url, headers=headers, data=payload)
        return response.json()
    except Exception as e:
        print(e)
        return "机器人出问题了，请稍后再试"
